console.log('你好，世界');

// 基本数据类型
let age: number = 18;
console.log(age);

let Name: string = 'Brave-Y';
console.log(Name);

let B: boolean = false;
console.log(B)

let N: null = null;
console.log(N);

let U: undefined = undefined;
console.log(U);

let S: symbol = Symbol();
console.log(S);

// 数组类型
let numbers: number[] = [1, 5, 6, 8];
let strings: Array<string> = ['a', 'b', 'c'];
console.log(numbers);
console.log(strings);

let arr: (number | string)[] = ['a', 1, 'b', 2, 'c', 3];
console.log(arr);
let arrs: number | string[] = ['a', 'b'];
console.log(arrs);

// 类型别名
type CustomArray = (number | string)[];
let arr1: CustomArray = ['x', 4, 'y', 5, 'z', 6];
let arr2: CustomArray = ['q', 7, 'w', 8, 'e', 9];
console.log(arr1);
console.log(arr2);


// 函数类型
function add1(num1: number, num2: number): number {
    return num1 + num2;
}
console.log(add1(1, 2));

const add2 = (num1: number, num2: number): number => {
    return num1 + num2;
}
console.log(add2(3, 4));

const add3: (num1: number, num2: number) => number = (num1, num2) => {
    return num1 + num2;
}
console.log(add3(5, 6));

// 如果函数没有返回值，则函数类型为void
function greet(name: string): void {
    console.log('你好', name);
}
greet('胖鸡');

// 可选参数，在可传可不传的参数后面添加void
function mySlice(start?: number, end?: number): void {
    console.log('起始索引', start, '结束索引', end);
}
mySlice(3, 5);


// 对象类型
let person: {
    name: string;
    age: number;
    sayHi(): void
} = {
    name: '胖鸡',
    age: 18,
    sayHi() {
        console.log('你好!')
    }
}

// 对象类型案例--封装axios
// 可选语法，请求地址必填，请求方法选填
function myAxios(config: {
    url: string;
    method?: string
}) {
    console.log(config)
}
